<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type='text/javascript' src='../dayjs.min.js'></script>
    <script type='text/javascript' src='../vue.js'></script>
</head>
<body>
    <div id="root">
        <h1>显示格式化后的时间</h1>
        <h3> 现在是 {{timestamp | time('YYYY-MM-DD HH:mm:ss') | subSting}}</h3>
    </div>

    <script type='text/javascript'>
        //必须要写在 new Vue() 的前面
        Vue.filter('subSting',function(v){  
          return v.slice(0,4)
        })
        new Vue({ 
            el: '#root',
            data: {
                timestamp: Date.now()
            },
            filters: {
                time(v,fmt='YYYY年MM月DD日 HH时mm分ss秒'){
                   return dayjs(v).format(fmt)
                }
            }
        })
        //必须要写在 new Vue() 的前面
        //Vue.filter('subSting',function(v){  
        //   return v.slice(0,4)
        //})
       
    </script>
    
</body>
</html>